package com.sdtv.mediunfusion.mvp.ui.outsidetask.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.reflect.TypeToken;
import com.sdtv.mediunfusion.R;
import com.sdtv.mediunfusion.bean.FileBean;
import com.sdtv.mediunfusion.bean.TaskBean;
import com.sdtv.mediunfusion.utils.SharedPreUtils;
import com.sdtv.mediunfusion.utils.UploadStatus;
import com.sdtv.mediunfusion.utils.Utils;

import java.util.List;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.mediunfusion.mvp.ui.outsidetask.adapter
 * @ClassName: TaskListAdapter
 * @Description: java类作用描述
 * @Author: 小郭同学
 * @CreateDate: 2019-08-02 11:00
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class TaskListAdapter extends BaseQuickAdapter<TaskBean, BaseViewHolder> {


    public TaskListAdapter(int layoutResId, @Nullable List<TaskBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, TaskBean item) {
        helper.setText(R.id.task_titleView, item.getDistributionTaskTitle())
                .setText(R.id.task_timeView, item.getDistributionTaskTime());
        String status = item.getUserTaskStatus();
        ImageView statusImg = helper.getView(R.id.task_statusImg);
        //     是否撤销(0：进行中；1：已完成；2：撤销中；3：已撤销 4：d待领取
        switch (status) {
            case "0":
                statusImg.setImageResource(R.mipmap.jinxingzhong);
                break;
            case "1":
                statusImg.setImageResource(R.mipmap.yiwancheng);
                break;
            case "2":
                statusImg.setImageResource(R.mipmap.chexiaozhong);
                break;
            case "3":
                statusImg.setImageResource(R.mipmap.yichexiao);
                break;
            case "4":
                statusImg.setImageResource(R.mipmap.dailingqu);
                break;
            default:
        }
        String tag = Utils.getSharePrefenceKey("uploadingList" + item.getDistributionTaskKey());
        List<FileBean> localList = SharedPreUtils.getDataList(mContext, tag, new TypeToken<List<FileBean>>() {
        }.getType());
        if (!localList.isEmpty()) {
            FileBean videoBean = localList.get(localList.size() - 1);
            String percent = videoBean.getPercent();
            int uploadStatus = videoBean.getFileStatus();
            String status_in_cn = "";
            switch (uploadStatus) {
                case UploadStatus.UPLOAD_STATUS_INIT:
                    status_in_cn = "准备上传";
                    break;
                case UploadStatus.UPLOAD_STATUS_UPLOADING:
                    status_in_cn = "上传中";
                    if (!TextUtils.isEmpty(percent)) {
                        status_in_cn = "已上传" + percent + "%";
                    }
                    break;
                case UploadStatus.UPLOAD_STATUS_ERROR:
                    status_in_cn = "上传失败";
                    // 设置字体颜色

                    break;
                case UploadStatus.UPLOAD_STATUS_COMPLETED:
                    status_in_cn = "上传完成";
                    break;
                case UploadStatus.UPLOAD_STATUS_PAUSE:
                    status_in_cn = "暂停中";
                    if (!TextUtils.isEmpty(percent)) {
                        status_in_cn = "已上传" + percent + "%";
                    }
                    break;
            }
            helper.setText(R.id.task_uploadStatusView, status_in_cn)
                    .setVisible(R.id.task_uploadStatusView, true);
        } else {
            helper.setVisible(R.id.task_uploadStatusView, false);
        }


    }


}
